package org.hang.jvm.classfile.constantpool;

import lombok.Getter;
import lombok.Setter;
import org.hang.jvm.classfile.ClassReader;
import org.hang.jvm.classfile.constantpool.impl.ConstantClassInfo;

/**
 * 说明
 *
 * @author 廖景航
 * @date created on 2022/3/10 下午4:43
 */
public class ConstantPool {

    @Getter
    @Setter
    private ConstantInfo[] constantInfos;

    @Getter
    private final int size;

    public ConstantPool(ClassReader reader) {
        size = reader.readUint16();
        constantInfos = new ConstantInfo[size];
        for (int i = 1; i < size; i++) {
            constantInfos[i] = ConstantInfo.readConstantInfo(reader, this);
            switch (constantInfos[i].tag()) {
                case ConstantInfo.CONSTANT_TAG_DOUBLE:
                case ConstantInfo.CONSTANT_TAG_LONG:
                    i++;
                    break;
            }
        }

    }

    public String getClassName(int supperClassIdx) {
        ConstantClassInfo classInfo = (ConstantClassInfo) this.constantInfos[supperClassIdx];
        return this.getUTF8(classInfo.nameIdx);
    }

    public String getUTF8(int nameIdx) {
        return null;
    }
}
